package config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import spitter.Spitter;

/**
 * config
 * 通过 DispatcherServlet启用的应用上下文
 * 一般包含 web组件的Bean，如 处理器映射器、处理器 、视图解析器等。
 * 如果将 web组件，配置在RootConfig中，会怎么样？
 * 2018/9/25-15:11
 * 科达科技股份有限公司-版权所有
 * Created by wuqiang on 15:11.
 */
@Configuration
@EnableWebMvc //启用注解驱动的mvc
@ComponentScan(basePackageClasses = Spitter.class)
public class WebConfig extends WebMvcConfigurerAdapter {
    /**
     * 配置视图解析器
     * @return
     */
    @Bean
    public ViewResolver viewResolver(){
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }

    /**
     * 配置静态资源
     * @param configurer
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
}
